package com.handa.admin.userservice.controller;

import com.handa.admin.userservice.common.exception.ServiceException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用来测试 多个Feign 调用时，如何异步处理的问题
 */

@RestController
@RequestMapping("/Admin/FeignTest")
public class FeignTestController {

    @GetMapping("test0")
    public Integer test0(Long millSec) {
        try {
            Thread.sleep(millSec);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return 1;
    }

    @GetMapping("test1")
    public Integer test1() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return 1;
    }

    @GetMapping("test2")
    public Integer test2() {
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return 2;
    }


    @GetMapping("test3")
    public Integer test3() {
        try {
            Thread.sleep(7000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return 3;
    }


    @GetMapping("test4")
    public Integer test4() {
        try {
            Thread.sleep(8000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return 4;
    }

    @GetMapping("test5")
    public Integer test5() {
        try {
            Thread.sleep(1000);
            throw new ServiceException("超时了");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

}
